home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Prog / A / AntiAliasMan.sit / Libraries / AntiAliasMan / AntiAliasMan Tester / Generic.c < prev   
Encoding:
C/C++ Source or Header  |  1994-08-21  |  3.5 KB  |  200 lines  |  [TEXT/KAHL]

  1. void        ToolBoxInit(void);
  2. void        MenuBarInit(void);
  3. void        ResInit(void);
  4. void        WindowInit(void);
  5. void        EventLoop(void);
  6. void        DoEvent(EventRecord *eventPtr);
  7. void        HandleMouseDown(EventRecord *eventPtr);
  8. void        HandleMenuChoice(long menuChoice);
  9. void        DoUpdate(WindowPtr window);
  10. void        CloseMeWindow(WindowPtr doomedWindow);
  11. void        StrCopy(ConstStr255Param s1,Str255 s2);
  12. void        DrawAntiAliasManString(ConstStr255Param s);
  13.  
  14. WindowPtr    gWindow;
  15.  
  16. void        main(void)
  17. {
  18.     ToolBoxInit();
  19.     MenuBarInit();
  20.     WindowInit();
  21.  
  22.     EventLoop();
  23. }
  24.  
  25. void        ToolBoxInit(void)
  26. {
  27.     InitGraf(&thePort);
  28.     InitWindows();
  29.     InitFonts();
  30.     InitMenus();
  31.     TEInit();
  32.     InitDialogs(nil);
  33.     InitCursor();
  34. }
  35.  
  36. void        MenuBarInit(void)
  37. {
  38.     Handle        menuBar;
  39.     MenuHandle    menu;
  40.  
  41.     menuBar=GetNewMBar(128);
  42.     SetMenuBar(menuBar);
  43.  
  44.     menu=GetMHandle(128);
  45.     AddResMenu(menu,'DRVR');
  46.  
  47.     DrawMenuBar();
  48. }
  49.  
  50. void        WindowInit(void)
  51. {
  52.     Rect    theRect;
  53.  
  54.     SetRect(&theRect,20,60,600,190);
  55.     gWindow=NewCWindow(nil,&theRect,nil,true,0,(WindowPtr)-1L,true,(long)nil);
  56.     SetPort(gWindow);
  57. }
  58.  
  59. void        EventLoop(void)
  60. {
  61.     EventRecord    event;
  62.  
  63.     while(1)
  64.     {
  65.         while(!WaitNextEvent(everyEvent,&event,20L,nil));
  66.         DoEvent(&event);
  67.     }
  68. }
  69.  
  70. void        DoEvent(EventRecord *eventPtr)
  71. {
  72.     char        theChar;
  73.     WindowPtr    window;
  74.  
  75.     switch(eventPtr->what)
  76.     {
  77.         case mouseDown:
  78.             HandleMouseDown(eventPtr);
  79.             break;
  80.         case keyDown:
  81.         case autoKey:
  82.             theChar=eventPtr->message &charCodeMask;
  83.             if(eventPtr->modifiers &cmdKey) HandleMenuChoice(MenuKey(theChar));
  84.             break;
  85.         case updateEvt:
  86.             window=(WindowPtr)eventPtr->message;
  87.             DoUpdate(window);
  88.             break;
  89.     }
  90. }
  91.  
  92. void        HandleMouseDown(EventRecord *eventPtr)
  93. {
  94.     WindowPtr    whichWindow;
  95.     short        thePart;
  96.     long        menuChoice;
  97.     Point        thePt;
  98.  
  99.     thePart=FindWindow(eventPtr->where,&whichWindow);
  100.     switch(thePart)
  101.     {
  102.         case inMenuBar:
  103.             menuChoice=MenuSelect(eventPtr->where);
  104.             HandleMenuChoice(menuChoice);
  105.             HiliteMenu(false);
  106.             break;
  107.         case inSysWindow:
  108.             SystemClick(eventPtr,whichWindow);
  109.             break;
  110.         case inContent:
  111.             SetPort(whichWindow);
  112.             SelectWindow(whichWindow);
  113.             thePt=eventPtr->where;
  114.             GlobalToLocal(&thePt);
  115.             break;
  116.         case inDrag:
  117.             DragWindow(whichWindow,eventPtr->where,&qd.screenBits.bounds);
  118.             break;
  119.         case inGoAway:
  120.             if(TrackGoAway(whichWindow,eventPtr->where)) CloseMeWindow(whichWindow);
  121.             break;
  122.     }
  123. }
  124.  
  125. void        HandleMenuChoice(long menuChoice)
  126. {
  127.     short        menu,item;
  128.     Str255        dAName;
  129.     MenuHandle    appleMenu;
  130.     GrafPtr        savePort;
  131.  
  132.     menu=HiWord(menuChoice);
  133.     item=LoWord(menuChoice);
  134.  
  135.     switch(menu)
  136.     {
  137.         case 128:
  138.             if(item==1);
  139.             else
  140.             {
  141.                 appleMenu=GetMHandle(128);
  142.                 GetPort(&savePort);
  143.                 GetItem(appleMenu,item,dAName);
  144.                 OpenDeskAcc(dAName);
  145.                 SetPort(savePort);
  146.             }
  147.             break;
  148.         case 129:
  149.             if(item==1) CloseMeWindow(FrontWindow());
  150.             if(item==2) ExitToShell();
  151.             break;
  152.         case 130:
  153.             break;
  154.     }
  155. }
  156.  
  157. void        DoUpdate(WindowPtr window)
  158. {
  159.     Rect    theRect;
  160.  
  161.     BeginUpdate(window);
  162.     if(window==gWindow)
  163.     {
  164.         SetPort(gWindow);
  165.         BackColor(blackColor);
  166.         EraseRect(&gWindow->portRect);
  167.         ForeColor(blueColor);
  168.         MoveTo(10,82);
  169.         TextFace(0);
  170.         TextFont(20);
  171.         TextSize(72);
  172.         DrawAAString("\pAntialiasing:");
  173.         TextFont(4);
  174.         DrawAAString("\pYeah!");
  175.         MoveTo(10,116);
  176.         TextSize(24);
  177.         DrawAAString("\pBrought to you in part by Slackers, Inc.");
  178.     }
  179.     EndUpdate(window);
  180. }
  181.  
  182. void        CloseMeWindow(WindowPtr doomedWindow)
  183. {
  184.     MenuHandle    menu;
  185.  
  186.     CloseWindow(doomedWindow);
  187.     DisposeGrafPort(doomedWindow);
  188.     if(FrontWindow()==nil)
  189.     {
  190.         menu=GetMHandle(129);
  191.         DisableItem(menu,1);
  192.     }
  193. }
  194.  
  195. void        StrCopy(ConstStr255Param s1,Str255 s2)
  196. {
  197.     short    i;
  198.  
  199.     for(i=0;i<=s1[0];i++) s2[i]=s1[i];
  200. }